package cn.xuanxuanyuhua.crm.domain;

import cn.xuanxuanyuhua.crm.util.DateUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class CustomerTraceHistory extends BaseDomain {
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date traceTime;

    private String traceDetails;

    private Integer traceResult;

    private String remark;

    private Date inputTime;

    private SystemDictionaryItem traceType;

    private Customer customer;

    private Employee inputUser;

    public String getTraceResultName(){
        String msg = "优";
        if(traceResult == 2){
           msg = "中";
        }else if(traceResult == 1){
            msg = "差";
        }
        return msg;
    }

    public String getJson() throws JsonProcessingException {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",customer.getName());
        map.put("traceTime", DateUtil.formatDate(traceTime));
        map.put("traceDetails",traceDetails);
        map.put("traceTypeId",traceType.getId());
        map.put("traceResult",traceResult);
        map.put("remark",remark);
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(map);
    }

}